#coding:utf-8
import sys, os, re
import time
import datetime
sys.path.append(".")

from config import *
from utils.jieba_wrapper import *
from utils.utils import *

from utils.wordtool import *
from utils import text_utils
from utils import lang_area_utils
from utils.datetime_utils import *
from utils.pinyin import *

from algo.parse_name import *
from algo.videoname_utils import *

"""
category_name:关键词
儿童、动画、剧情、电影、院线、综艺
"""

def check_delflag( delflag ):
    if delflag > 0.99:
        delflag = 1
    elif delflag < 0.01:
        delflag = 0
    else:
        delflag = 0.5
    return delflag
    

global_part_words = {'上部':1, '下部':1, '中部':1}
global_part_words['第2篇']= 1
global_part_words['第3篇']= 1
global_part_words['第4篇']= 1
global_part_words['第5篇']= 1
global_part_words['第6篇']= 1
global_part_words['第7篇']= 1
global_part_words['第8篇']= 1
global_part_words['第9篇']= 1
global_part_words['第10篇']= 1
global_part_words['第11篇']= 1
global_part_words['第12篇']= 1
global_part_words['第13篇']= 1
global_part_words['第14篇']= 1
global_part_words['第15篇']= 1
global_part_words['第2辑']= 1
global_part_words['第3辑']= 1
global_part_words['第4辑']= 1
global_part_words['第5辑']= 1
global_part_words['第6辑']= 1
global_part_words['第7辑']= 1
global_part_words['第8辑']= 1
global_part_words['第9辑']= 1
global_part_words['第10辑']= 1
global_part_words['第11辑']= 1
global_part_words['第12辑']= 1
global_part_words['第13辑']= 1
global_part_words['第14辑']= 1
global_part_words['第15辑']= 1

global_part_words['第2话']= 1
global_part_words['第3话']= 1
global_part_words['第4话']= 1
global_part_words['第5话']= 1
global_part_words['第6话']= 1
global_part_words['第7话']= 1
global_part_words['第8话']= 1
global_part_words['第9话']= 1
global_part_words['第10话']= 1
global_part_words['第11话']= 1
global_part_words['第12话']= 1
global_part_words['第13话']= 1
global_part_words['第14话']= 1
global_part_words['第15话']= 1
global_part_words['第2部']= 1
global_part_words['第3部']= 1
global_part_words['第4部']= 1
global_part_words['第5部']= 1
global_part_words['第6部']= 1
global_part_words['第7部']= 1
global_part_words['第8部']= 1
global_part_words['第9部']= 1
global_part_words['第10部']= 1
global_part_words['第11部']= 1
global_part_words['第12部']= 1
global_part_words['第13部']= 1
global_part_words['第14部']= 1
global_part_words['第15部']= 1
global_part_words['第2季']= 1
global_part_words['第3季']= 1
global_part_words['第4季']= 1
global_part_words['第5季']= 1
global_part_words['第6季']= 1
global_part_words['第7季']= 1
global_part_words['第8季']= 1
global_part_words['第9季']= 1
global_part_words['第10季']= 1
global_part_words['第11季']= 1
global_part_words['第12季']= 1
global_part_words['第13季']= 1
global_part_words['第14季']= 1
global_part_words['第15季']= 1

class Similarity(object):
    """
    1 - 播放源绑定
    2 - 知识库绑定
    3 - 又名挖掘
    """
    __slots__ = ( 'album', 'video', 'enum_pattern', '_xnames', '_ynames', 'cate_delflag')

    def __init__(self, _album, _video):

        if not isinstance(_album, dict):
            return 
        if not isinstance(_video, dict):
            return 

        self.album = _album
        self.video = _video
        ####self.grade = _grade

        self.enum_pattern = re.compile('[0-9]+')

    def infer_lang_delflag(self, diff_words ):
        """ 根据语言规则推导是否拆分标记 """
        if not diff_words:
            return 0
        if config_match != 1: #只有专辑层次上的绑定才判断语言 
            return 0

        for w in diff_words:
            if w in lang_area_utils.lang_words_dict:
                return 0.5
            if len(w) <= 6: 
                continue
            if not w.endswith('语版') and not w.endswith('文版'):
                continue
            if w == '国语版' or w == '中文版' or w == '汉语版' or w == '普通话版' or w == '汉语普通话版': 
                continue
            return 0.5
        return 0
    def get_video_type(self):
        """ 2017-02-19新增"""
        vt = self.album.get('video_type', 0 )
        if vt:
            return vt
        vt = self.video.get('video_type', 0 )
        if vt:
            return vt

        return 0

    def get_features(self):
        features = {}
        name = self.album.get('name')
        xname = name
        if isinstance(name, str):
            name = name.decode('utf-8', 'ignore')
        #xname = name
        name = self.video.get('name')
        yname = name
        if isinstance(name, str):
            name = name.decode('utf-8', 'ignore')

        #yname = name
        #简介
        features['intro_sim'] = self.get_intro_ratio()
        #地区
        features['area_sim'] = self.get_area_ratio()
        #语言
        features['lan_sim'] = self.get_lang_ratio()
        #分类
        features['cate_sim'], shortMovie = self.get_category_ratio()
        #集数
        features['epi_same'] = self.get_number_ratio()
        #日期和年份
        date_score, year_diff = self.get_time_ratio()
        features['date_same'] = date_score
        if date_score >0.99 and year_diff < 0:
            year_diff = 0 
         
        features['year_diff'] = year_diff

        #提取简介中的人名
        self._xnames, self._ynames = self.ext_intro_name()
        
        #导演
        director, com, total = self.get_people_ratio('director_name')
        features['director_sim'] = director
        if features['director_sim'] < 0:
            features['director_sim'] /= 2.0
        features['director_com'] = com
        features['director_all'] = total

        #人物的国家有没交集

        #演员
        actor, com, total = self.get_people_ratio('actor_name')
        features['actor_sim'] = actor
        if features['actor_sim'] < 0:
            features['actor_sim'] /= 4.0
        features['actor_com'] = com
        features['actor_all'] = total

        #类型
        video_type = self.get_videotype_ratio()
        features['vtype_sim'] = video_type

        #标题
        name_cmp = VideoNameSim(self.album, self.video )
        score_name = name_cmp.parse()
        features['title_sim'] = score_name

        ##todo
        delflag = name_cmp.filte_by_name( year_diff )
        delflag = check_delflag( delflag )

        #语版
        diff_words = name_cmp.get_diff_words()
        if delflag < 0.1:
            delflag = self.infer_lang_delflag( diff_words )
        
        #修正年份
        ################################################################
        xyearwords, yyearwords = [], []
        xyear = self.album.get('screen_year', None)
        if xyear is None: xyear = ''

        if isinstance(xyear, int): xyear = str(xyear)

        years = re.findall('[0-9]+', xyear)
        for year in years:
            if len(year) != 4: continue
            if int(year) < 1900: continue
            if int(year) > 2020: continue
            xyearwords.append( year )

        yyear = self.video.get('screen_year', None)
        if yyear is None: yyear = ''
        if isinstance(yyear, int): yyear = str(yyear)
        years = re.findall('[0-9]+', yyear)
        for year in years:
            if len(year) != 4: continue
            if int(year) < 1900: continue
            if int(year) > 2020: continue
            yyearwords.append( year )

        xname = self.album.get('name', '')
        yname = self.video.get('name', '')
        for w in diff_words:
            if not w.isdigit(): continue
            if len(w) < 4: continue
            yearword = int(w[:4])
            if yearword < 1980: continue
            if yearword > 2020: continue

            yearword = str(yearword)
            if yearword in xname:
                xyearwords.append( yearword )
            elif yearword in yname:
                yyearwords.append( yearword )
        if year_diff is None:
            if xyearwords and yyearwords:
                xy = int(xyearwords[0])
                yy = int(yyearwords[0])
                year_diff = abs(xy-yy)
                features['year_diff'] = year_diff

        ################################################################
        features['diffnum'] = len( diff_words )
        #print 'diff = ', ';'.join( diff_words )

        if features['diffnum'] > 0 and features['title_sim'] > 0.99:
            features['title_sim'] *= 0.99

        features['delflag'] = delflag

        #差异词: 2017-02-20
        if '下' in diff_words or '上' in diff_words :
             if  features['delflag'] <= 0.01:
                 features['delflag'] = 0.5

        if diff_words and features['delflag'] <= 0.001:
            for w in diff_words:
                if w in global_part_words:
                    features['delflag'] = 0.5
                    if features['title_sim'] >= 0.799:
                        features['title_sim'] *= 0.95

                    break

        #相同才给出类型: 2017-02-19新增
        features['video_type'] = self.get_video_type()
        #2017-02-19新增
        if features['vtype_sim'] or features['video_type'] == 2:
            if name_cmp.is_ShortMovie():
                features['video_type'] = -2
            elif shortMovie:
                features['video_type'] = -2

            ###短片/短视频／微电影／微影院

        features['cate_err'] = 0
        if features['video_type'] <= 2 and name_cmp.get_cateword_flag():
            features['cate_err'] = 1

        #年份归一处理: 未知、相同、差１年、差２年、差３年、差４年、差５年以上，差１０年以上
        if features['year_diff'] is None:
            features['year_diff'] = 0
        elif features['year_diff'] == 0:
            features['year_diff'] = 1
        elif features['year_diff'] > 0:
            if features['year_diff'] > 10:
                features['year_diff'] = 10
            features['year_diff'] = -features['year_diff']

        if features['director_com']>4:
            features['director_com'] = 4
        if features['actor_com'] > 5:
            features['actor_com'] = 5

        #版本一样的情况
        features['part_ok'] = name_cmp.is_part_match()

        # 年份差一年，季或部一致， 标题完全相同
        if features['part_ok'] ==1 and features['title_sim'] >= 0.9999 and features['year_diff'] == -1 and features['video_type'] in ['4', 4]:
            features['year_diff'] = 0
        elif features['part_ok'] > 0.99 and features['title_sim'] >= 0.99 and features['intro_sim'] and features['intro_sim'] > 0.80 and features['video_type'] in [4, '4']:
            features['year_diff'] = 0
        elif features['part_ok'] > 0.99 and features['title_sim'] >= 0.99 and features['director_sim'] >= 0.5 and features['video_type'] in [4, '4']:
            features['year_diff'] = 0

        #规则：
        if features['delflag'] <= 0.01 and features['video_type'] in [1, '1', '2', 2]:
            if isinstance(xname, str):
                xname = xname.decode('utf-8', 'ignore')
            if isinstance(yname, str):
                yname = yname.decode('utf-8', 'ignore')
            if xname.find(u'精彩周边') != -1 and yname.find(u'精彩周边') == -1:
                features['delflag'] = 1.0
            elif xname.find(u'精彩周边') == -1 and yname.find(u'精彩周边') != -1:
                features['delflag'] = 1.0
            elif xname.find(u'纪录片') != -1 and yname.find(u'纪录片') == -1:
                features['delflag'] = 0.5
            elif xname.find(u'纪录片') == -1 and yname.find(u'纪录片') != -1:
                features['delflag'] = 0.5
        if self.cate_delflag:
            features['delflag'] = 1
        if name_cmp.get_title_year_match():
            features['year_diff'] = 1
			
        if features['title_sim'] >= 0.90 and features['year_diff']<0 and features['video_type'] in [4,'4']:
            if isinstance(xname, unicode):
                xname = xname.encode('utf-8', 'ignore')
            if isinstance(yname, unicode):
                yname = yname.encode('utf-8', 'ignore')
            xyears = re.findall('^[0-9]{4,}', xname)
            yyears = re.findall('^[0-9]{4,}', xname)
            if xyears and yyears and xyears[0] == yyears[0]:
                xyear = xyears[0][:4]
                if int(xyear) >= 2000 and int(xyear) <= 2020: 
                    features['year_diff'] = 0
        ####创意剪辑
        #print xname, yname
        return features        

    def ext_intro_name(self):
        """　补充名字　"""
        key = 'intro'
        if key not in self.album and 'description' in self.album:
            key = 'description'

        xline = self.album.get(key, '')
        yactors = self.video.get('actor_name', '')
        xnames = text_utils.extact_intro_names( xline,yactors )

        yline = self.video.get( key, '')
        xactors = self.album.get('actor_name', '')
        ynames = text_utils.extact_intro_names( yline, xactors )

        return xnames, ynames

    def get_people_ratio(self, key ):
        xdirectors = self.album.get( key, '')
        if not xdirectors:
            xdirectors = ''
        if isinstance(xdirectors, unicode):
            xdirectors = xdirectors.encode('utf-8', 'ignore')
        if xdirectors in not_names:
            xdirectors = ''

        ydirectors = self.video.get( key, '')
        if not ydirectors:
            ydirectors = ''
        if isinstance( ydirectors, unicode):
            ydirectors = ydirectors.encode('utf-8', 'ignore')
        if ydirectors in not_names:
            ydirectors = ''

        x = xdirectors.replace('演员','').replace('(女)', '').replace('/', ';').replace('、', ';')
        x = x.replace(',', ';').replace('，',';')
        x = x.replace('（歌手）', '').replace('|', ';').replace(',',';').split(';')
        y = ydirectors.replace('演员','').replace('(女)', '').replace('/', ';').replace('、', ';')
        y = y.replace(',', ';').replace('，',';')
        y = y.replace('（歌手）', '').replace('|', ';').replace(',',';').split(';')
        xnames, ynames = {},{}
        is_eng1, is_eng2 = 1, 1
        for name in x:
            name = wordTool.get_peopple_map( name )
            name = name.replace('-', '').replace('·', '').replace(' ', '').strip()
            if len(name) <= 3: continue
            if name.isdigit(): continue
            if name in not_names: continue
            if not is_english_line( name ):
                is_eng1 = 0
            xnames[ name] = 1
        for name in y:
            name = wordTool.get_peopple_map( name )
            name = name.replace('-', '').replace('·', '').replace(' ', '').strip()
            if len(name) <= 3: continue
            if name.isdigit(): continue
            if name in not_names: continue
            if not is_english_line( name ):
                is_eng2 = 0
            ynames[ name] = 1
        
        #转拼音
        xnames = [ gpy.hanzi2pinyin_split(string=na, split="-") for na in xnames ]
        ynames = [ gpy.hanzi2pinyin_split(string=na, split="-") for na in ynames ]

        ####无法判别
        xnum = len(xnames)
        ynum = len(ynames)
        if xnum == 0 and ynum == 0:
            return 0, 0, 0

        hash1, hash2 = {}, {}
        #一方
        for name in xnames:
            hash1[name] = 1 
        if key == 'actor_name':
            for name in self._xnames:
                name = gpy.hanzi2pinyin_split(string=name, split="-")
                hash1[name] = 1 

        #另一方
        for name in ynames:
            hash2[name] = 1 
        if key == 'actor_name':
            for name in self._ynames:
                name = gpy.hanzi2pinyin_split(string=name, split="-")
                hash2[name] = 1 

        allhit = 0
        for name in xnames:
            if name in hash2:
                allhit += 1
        for name in ynames:
            if name in hash1:
               allhit += 1
        
        if xnum > 0 and ynum > 0 and allhit <= 0:
            #请判断另一方是否是英文 .....
            if is_eng1 or is_eng2:
                if is_eng1 != is_eng2:
                    return 0,0,0 
            if len(xdirectors) <= 9 and ydirectors.find(xdirectors) > 0:
                return 0,0,0 
            elif len(ydirectors) <= 9 and  xdirectors.find(ydirectors) > 0:
                return 0,0,0 
            #按标点分割再比较
            xwords = split_get_words( xdirectors ) 
            ywords = split_get_words( ydirectors ) 
            if xwords and ywords:
                com = set(xwords).intersection(set(ywords))
                tot = set(xwords).union(set(xwords))
                diff = list(tot.difference( com ) )
                if len(com) > 0:
                    r = len(com)  / (len(tot)+0.0)
                    if r >= 0.5:
                        tot = xnum+ynum
                        com = int(tot * r)
                        return r,com, tot
                    else:
                        return 0,0,0
            #print '|'.join(xwords), '\t', '|'.join(ywords)
            if xnum == 1 and xwords and xwords[0].find('卫视') != -1:
                return 0,0,0
            elif xnum == 1 and xwords  and xwords[0].find('电视台') != -1:
                return 0,0,0
            elif xnum == 1 and xwords  and xwords[0].endswith('频道'):
                return 0,0,0
            elif ynum == 1 and ywords and ywords[0].find('卫视') != -1:
                return 0,0,0
            elif ynum == 1 and ywords and ywords[0].find('电视台') != -1:
                return 0,0,0
            elif ynum == 1 and ywords and ywords[0].endswith('频道') :
                return 0,0,0
            return -(xnum+ynum)/2.0, 0, (xnum+ynum)

        if allhit <= 0:
            return 0, 0, 0
        if xnum == 0:
            return ( allhit + 0.0 )/ ynum, allhit, (xnum+ynum)
        if ynum == 0:
            return ( allhit + 0.0 )/ xnum, allhit, (xnum+ynum)

        allnum = xnum + ynum

        oldnum = allnum

        if allnum >= 8: allnum = 8
        ratio = (allhit+0.0)/ allnum

        com = allhit / 2
        if ratio >= 1.0: 
            ratio = 1.0
        if allhit < oldnum and ratio >= 0.999:
            ratio = 0.9
        return ratio, com, (xnum+ynum)


    def get_intro_ratio(self): 
        """简介:提前分词"""

        key = 'intro'
        if key not in self.album and 'description' in self.album:
            key = 'description'

        xline, yline = [], []
        if 'segwords' in self.album:
            xline = self.album['segwords']
        else:
            xline = self.album.get( key, '')
            if not xline:
                xline = []
            else:
                xline = cutwords(xline )

        if 'segwords' in self.video:
            yline = self.video['segwords']
        else:
            yline = self.video.get( key, '')
            if not yline:
                yline = []
            else:
                yline = cutwords(yline )

        if not xline or not yline:
            return None

        xnames = self.album.get('actor_name', '')
        if not xnames:
            xnames = ''

        ynames = self.video.get('actor_name', '')
        if not xnames:
            ynames = ''
        
        sc = text_utils.score_intro( xline, yline, xnames, ynames )

        return sc

    def get_number_ratio(self):
        """ 集数 """
        num1 = self.album.get('episodes',0)
        num2 = self.video.get('episodes',0)
        if isinstance(num1, int):
            if num1 < 10:
                num1 = ''
                return 0
            else:
                num1 = str(num1)
        if isinstance(num2, int):
            if num2 < 10:
                num2 = ''
                return 0
            else:
                num2 = str(num2)
        if isinstance(num1, unicode):
            num1 = num1.encode('utf-8', 'ignore')
        if isinstance(num2, unicode):
            num2 = num2.encode('utf-8', 'ignore')

        if not isinstance(num1, str):
            return 0
        if not isinstance(num2, str):
            return 0
        num1s = self.enum_pattern.findall(num1)
        num2s = self.enum_pattern.findall(num2)

        if len(num1s) != 1:
            return 0 

        if len(num2s) != 1:
            return 0 

        if num1s[0] == num2s[0]:
            return 1

        return 0

    def get_videotype_ratio(self): 
        """ 分类 """
        x = self.album.get('video_type',0)
        y = self.video.get('video_type',0)
        if not x or not y:
            return 0
        if x == y:
            return 1
        return 0

    def get_category_ratio(self): 
        """ 分类 """
        self.cate_delflag = 0
        xlang = self.album.get('category_name',u'')
        ylang = self.video.get('category_name',u'')
        if not xlang: 
            xlang = u''
        if not ylang: 
            ylang = u''

        if isinstance(xlang, str):
            xlang = xlang.decode('utf-8', 'ignore')
        if isinstance(ylang, str):
            ylang = ylang.decode('utf-8', 'ignore')

        if xlang.find(u'创意剪辑') != -1 and ylang.find(u'创意剪辑') == -1:
            self.cate_delflag = -1
        elif xlang.find(u'创意剪辑') == -1 and ylang.find(u'创意剪辑') != -1:
            self.cate_delflag = -1

        shortMovie = False
        if isinstance(xlang, str) and xlang.find('微电影') != -1:
            shortMovie = True
        elif isinstance(xlang, unicode) and xlang.find(u'微电影') != -1:
            shortMovie = True
        elif isinstance(ylang, str) and ylang.find('微电影') != -1:
            shortMovie = True
        elif isinstance(ylang, unicode) and ylang.find(u'微电影') != -1:
            shortMovie = True
        ratio = lang_area_utils.score_category( xlang, ylang )
        return ratio, shortMovie

    def get_lang_ratio(self): 
        """ 语言 """
        xlang = self.album.get('language_name','')
        ylang = self.video.get('language_name','')
        ratio = lang_area_utils.score_lang( xlang, ylang )
        return ratio

    def get_area_ratio(self): 
        """ 地区 """
        xarea = self.album.get('area_name','')
        yarea = self.video.get('area_name','')
        ratio = lang_area_utils.score_area( xarea, yarea )
        return ratio

    def get_time_ratio(self): 
        xday = self.album.get('screen_time','')
        if isinstance(xday, unicode):
            xday = xday.encode('utf-8', 'ignore')

        yday = self.video.get('screen_time','')
        if isinstance(yday, unicode):
            yday = yday.encode('utf-8', 'ignore')

        video_type = self.get_video_type()
        #综艺
        if video_type in [ 4, '4' ]:
            if xday and xday.endswith('-01-01') :
                xday = xday[:-6]+"-06-30"
            if  yday and yday.endswith('-01-01') :
                yday = yday[:-6]+"-06-30"
        date_score, diffdays = dateTool.score_datetime( xday, yday )
        year_score = dateTool.score_year( xday, yday )
        #排除综艺
        if date_score == 1: 
            year_score = 0
            return date_score,year_score
        elif date_score == 0 and diffdays is not None and diffdays <= 60 and year_score == 1:
            #综艺类型: 新增
            video_type = self.get_video_type()
            if video_type not in [ 4, '4' ]:
                year_score = 0
            return date_score,year_score
        elif date_score == 0 and isinstance(year_score, int) and year_score > 0: 
            year_score = None

        xyear = self.album.get('screen_year', None)
        yyear = self.video.get('screen_year', None)
        vt = self.get_video_type()
        if not xyear or not yyear:
            if vt not in ['4', 4]:
                return date_score,year_score
            if year_score is not None:
                return date_score,year_score
            if not xyear and not yyear:
                return date_score,year_score
            tyear, tname = None, None
            if xyear:
                tyear = xyear
                tname = self.video.get('name', u'')
            else:
                tyear = yyear
                tname = self.album.get('name', u'')
            if isinstance(tyear, unicode):
                tyear = tyear.encode('utf-8', 'ignore')
            elif isinstance(tyear, int):
                tyear = str(tyear)

            if not tyear.isdigit(): 
                return date_score,year_score

            if len(tyear) != 4: 
                return date_score,year_score
            if int(tyear) > 2020 or int(tyear) < 1990: 
                return date_score,year_score

            if isinstance(tname, unicode):
                tname = tname.encode('utf-8', 'ignore')
            if not tname:
                tname = ''
            if tname.find( tyear) != -1:
                year_score = 0

            return date_score,year_score

        if isinstance(xday,str) and not xday.endswith('-01-01'):
            w = str(xyear)
            if xday.find(w) == -1:
                results =  re.findall('^[12][09][0-9]{2,2}-[01][0-9]-[0123][0-9]$', xday)
                if results:
                    xyear = results[0]

        if isinstance(yday,str) and not yday.endswith('-01-01'):
            w = str(yyear)
            if yday.find(w) == -1:
                results = re.findall('^[12][09][0-9]{2,2}-[01][0-9]-[0123][0-9]$', yday)
                if results:
                    yyear = results[0]

        year_diff = None
        if isinstance(xyear, int ) and isinstance( yyear, int):
            if xyear > 1900 and xyear < 2030 and yyear > 1900 and yyear < 2030:
                year_diff = abs(xyear - yyear)

        if year_diff is None:
            return date_score,year_score
        if year_diff >= 10:
            year_diff = 10
        if year_score is None:
            year_score = year_diff
        elif year_score > year_diff:
            year_score = year_diff

        if year_score is not None and year_score == 0 and date_score is not None and date_score < 0:
            date_score = 0

        return date_score,year_score

    def formatPart(self, word ):

        if isinstance(word, unicode):
            word = word.encode('utf-8', 'ignore')

        w = word
        if w.isdigit():
            w = int(w)
            return str(w)
        if w in self._romawords:
            w = self._romawords[w]
            return str(w)

        if isNumberStr( w ):
            w = fromHanDigit(w)
            return w

        if w.find('第') == -1:
            return w

        w = w.decode('utf-8', 'ignore')
        w = w[1:-1].encode('utf-8', 'ignore')
        if w.isdigit():
            w = int(w) 
            return str(w)
        sz = len(w.decode('utf-8', 'ignore'))
        if len(w) != 3 * sz:
            return word 
        w = fromHanDigit(w) 
        w = str(w)
        return w


if __name__ == '__main__':
    pass


